import 'dart:async';
import 'package:app/models/models.dart';
import 'package:app/models/response/comments_response.dart';
import 'package:app/models/response/presenters_response.dart';
import 'package:app/models/response/videos_response.dart';
import 'package:app/models/response/wonderful_response.dart';

import 'api.dart';

class ApiRepository {
  final ApiProvider apiProvider;
  ApiRepository({required this.apiProvider});

  Future<LoginResponse?> login(LoginRequest data) async {
    final res = await apiProvider.login('/login', data);
    if (res.statusCode == 200) {
      return LoginResponse.fromJson(res.body);
    }
  }

  Future<PresentersResponse?> getPresenters() async {
    final res = await apiProvider.getPresenters('/presenters');
    if (res.statusCode == 200) {
      return PresentersResponse.fromJson(res.body);
    }
  }

  Future<Wonderful?> getWonderfulList({page = 1}) async {
    final res =
        await apiProvider.getWonderfulList('/wonderfulList?page=${page}');
    if (res.statusCode == 200) {
      return Wonderful.fromJson(res.body);
    }
  }

  Future<Wonderful?> getNumericalList({page = 1}) async {
    final res = await apiProvider.getNumericalList('/numerical?page=${page}');
    if (res.statusCode == 200) {
      return Wonderful.fromJson(res.body);
    }
  }

  Future<comments?> getComments({page = 1}) async {
    final res = await apiProvider.getComments('/comments?page=${page}');
    if (res.statusCode == 200) {
      return comments.fromJson(res.body);
    }
  }

  Future<Videos?> getVideos({page = 1}) async {
    final res = await apiProvider.getVideos('/videos?page=${page}');
    if (res.statusCode == 200) {
      return Videos.fromJson(res.body);
    }
  }
}
